<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution Shared/ Branch
	Scripts shared by the MasterServer/ and ContentServer/ Branch of the Maxsi
	Distribution Server-Side Code Branches.
	
	database.php
	Include Header for access to a database that can be used by Maxsi Distribution.

****************************************************************************/

if (file_exists('addons/shared/database_password.php'))
{
require('addons/shared/database_password.php');
}
else
{
die('You need a addons/shared/database_password.php file with the content<br /><br />

&lt?php<br />
$md_db_host	=	"localhost:3306";<br />
$md_db_user	=	"YOUR_DB_USERNAME";<br />
$md_db_pass	=	"YOUR_DB_PASSWORD";<br />
$md_db_name	=	"YOUR_DB_NAME";<br />
$md_db_prefix	=	"md_";<br />
?&gt;

');
}

$md_db = @mysql_pconnect($md_db_host,$md_db_user, $md_db_pass);

unset($md_db_host);
unset($md_db_user);
unset($md_db_pass);

// If we have a database, simply proceed.
if ($md_db)
{
	mysql_select_db($md_db_name, $md_db);

	$md_sql=array();
	$md_sql_row=array();
	$md_sql_total=array();
	$md_sql_slots=array();
	
	function md_sql($sqlcode,$once = false)
	{
		global $md_sql;
		global $md_sql_row;
		global $md_sql_total;
		global $md_sql_slots;
		global $md_db;
		$slot=md_getfreesqlslot();
		$md_sql_slots[$slot]=1;
		$md_sql[$slot] = mysql_query($sqlcode, $md_db);
		if ( $md_sql[$slot] == false )
		{
			die("Error in MySQL Query: ".$sqlcode);
		}
		else
		{
			if ($once == false)
			{
				$md_sql_row[$slot] = mysql_fetch_assoc($md_sql[$slot]);
				$md_sql_total[$slot] = mysql_num_rows($md_sql[$slot]);
			}
		}
		return $slot;
	}
	// If no response is expected, use this.
	function md_sql_once($sqlcode)
	{
		$slotty = md_sql($sqlcode,true);
		md_clearslot($slotty);
	}
	function md_sql_next($slot)
	{
		global $md_sql;
		global $md_sql_row;
		$md_sql_row[$slot] = mysql_fetch_assoc($md_sql[$slot]);
	}
	function md_getfreesqlslot()
	{
		global $md_sql_slots;
		$counter=0;
		while ( isset($md_sql_slots[$counter]) && $md_sql_slots[$counter] == 1 )
		{
			$counter++;
		}
		
		return $counter;
	}
	function md_clearslot($slot)
	{
		global $md_sql_slots;
		$md_sql_slots[$slot]=0;
	}
	function md_GetDatabaseName($Name)
	{
		global $md_db_prefix;
		return $md_db_prefix.$Name;
	}
}
?>